﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="HomePage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="TheScriptManager" runat="server" LoadScriptsBeforeUI="false">
            <Services>
                <asp:ServiceReference Path="~/SimpleService.asmx" />
            </Services>
        </asp:ScriptManager>
        <AjaxLogging:ExceptionManager ID="TheExceptionManager" runat="server">
            <Listeners>
                <AjaxLogging:WebServiceListener ServicePath="~/ExceptionLogService.asmx" ServiceMethod="Log" />
                <AjaxLogging:PanelListener Panel="pnlException" />
                <AjaxLogging:SysDebugListener />
                <AjaxLogging:AlertListener />
            </Listeners>
        </AjaxLogging:ExceptionManager>
        <input type="button" value="Throw Web Service Error" onclick="return throwWebServiceError()" />
        <input type="button" value="Throw Regular Error" onclick="return throwRegularError()" />
        <input type="button" value="Throw Ajax Error" onclick="return throwAjaxError()" />
        <input type="button" value="Throw Unhandled Error" onclick="return throwUnhandledError()" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline">
            <ContentTemplate>
                <asp:Button ID="btnUpdatePanel" runat="server" Text="Throw Update Panel Error" OnClick="btnUpdatePanel_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <asp:Panel ID="pnlException" runat="server" style="background-color:#ffff00"></asp:Panel>
        <br />
        <textarea id='TraceConsole' rows="10" cols="160" style="width:100%"></textarea>
        <script type="text/javascript">

            var ERROR_CODE_BASE = 105000;
            var ERROR_CODE_WEB_SERVICE = (ERROR_CODE_BASE + 2);
            var ERROR_CODE_REGULAR = (ERROR_CODE_BASE + 3);
            var ERROR_CODE_USER_DEFINED = (ERROR_CODE_BASE + 4);

            function throwWebServiceError()
            {
                SimpleService.ThrowException (
                                                function(result)
                                                {
                                                    //Process the result
                                                },
                                                function(e)
                                                {
                                                    Ajax.Logging.ExceptionManager.getInstance().publishException(ERROR_CODE_WEB_SERVICE, e);
                                                }
                                            );
            }

            function throwRegularError()
            {
                try
                {
                    //The abc does not exist in the dom tree.
                    document.getElementById('abc').focus();
                }
                catch(e)
                {
                    Ajax.Logging.ExceptionManager.getInstance().publishException(ERROR_CODE_REGULAR, e);
                }
            }

            function throwAjaxError()
            {
                try
                {
                    throw Error.invalidOperation('Cannot invoke this method.');
                }
                catch(e)
                {
                    Ajax.Logging.ExceptionManager.getInstance().publishException(ERROR_CODE_USER_DEFINED, e);
                }
            }

            function throwUnhandledError()
            {
                //Fires the window.onerror event
                arrayDoesNotExists[1000] = 'bla bla';
            }
        </script>
    </form>
</body>
</html>